package com.woniu108.gateway.factory;

import lombok.Data;
import org.springframework.cloud.gateway.filter.GatewayFilter;
import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.cloud.gateway.filter.factory.AbstractGatewayFilterFactory;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

import java.util.Arrays;
import java.util.List;

@Component
public class TestGatewayFilterFactory extends AbstractGatewayFilterFactory<TestGatewayFilterFactory.TestParam> {


    public TestGatewayFilterFactory(){
        super(TestParam.class);
    }


    @Override
    public List<String> shortcutFieldOrder() {
        return Arrays.asList("key","value","name");
    }

    @Override
    public GatewayFilter apply(TestParam config) {
        return new GatewayFilter() {
            @Override
            public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
                System.out.println(config.getName()+":"+config.getKey()+":"+ config.getValue());
                return chain.filter(exchange);
            }
        };
    }

    @Data
    static class TestParam{
        private String name;
        private String key;
        private String value;
    }


}
